﻿
    using Microsoft.Phone.Controls;
    using System;
    using System.Runtime.InteropServices;
    using System.Windows;
namespace WCYCReader.Main
{
    public class NaviService
    {
        private readonly static Uri MainPage;

        static NaviService()
        {
            //NaviService.MainPage = new Uri("/Pages/MainPage.xaml", UriKind.Relative);
            //NaviService.MainPage = new Uri("/Pages/IndexPage.xaml", UriKind.Relative);
            NaviService.MainPage = new Uri("/IndexPage.xaml", UriKind.Relative);
        }

        public NaviService()
        {
        }

        public static Uri getNavigateUri(QQReaderPage page, string param = "")
        {
            Uri mainPage = null;
            switch (page)
            {
                case QQReaderPage.EMainPage:
                    {
                        mainPage = NaviService.MainPage;
                        break;
                    }
                case QQReaderPage.EBookChapterPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/BookChapterPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EAboutPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/AboutPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EFeedbackPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/FeedbackPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EBookRecommendPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/BookRecommendPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EBookRankPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/BookRankPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EBookTypePage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/BookTypePage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EBookSearchPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/SearchPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EBookCityListPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/BookCityListPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EBookDetailPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/BookDetailPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EBookReaderPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/BookReaderPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EBookHelpPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/HelpPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EDownloadManagerPage:
                    {
                        mainPage = new Uri(string.Concat("/Pages/DownloadManagerPage.xaml", param), UriKind.Relative);
                        break;
                    }
                case QQReaderPage.EBookSearchRankPage:
                    mainPage = new Uri(string.Concat("/Pages/BookSearchRankPage.xaml", param), UriKind.Relative);
                    break;
                case QQReaderPage.EBookImportPage:
                    mainPage = new Uri(string.Concat("/Pages/BookImportPage.xaml", param), UriKind.Relative);
                    break;
                case QQReaderPage.EBookIntoPage:
                    mainPage = new Uri(string.Concat("/Pages/BookIntoPage.xaml", param), UriKind.Relative);
                    break;
                case QQReaderPage.EPCAddressPage:
                    mainPage = new Uri(string.Concat("/Pages/PCAddressPage.xaml", param), UriKind.Relative);
                    break;
                case QQReaderPage.EExplorerPage:
                    mainPage = new Uri(string.Concat("/Pages/ExplorerPage.xaml", param), UriKind.Relative);
                    break;        
            }
            return mainPage;
        }

        public static bool Navigate(QQReaderPage page, string param = "")
        {
            Uri navigateUri = NaviService.getNavigateUri(page, param);
            if (!(Application.Current.RootVisual is PhoneApplicationFrame))
            {
                return false;
            }
            return ((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(navigateUri);
        }
    }
}

